

# Script for: Citizens' Preferences for Liberal Democracy and its Deformations. 
#
# Version: May 10, 2022
#
# Author: Pascal D. K�nig



#### Load packages ####

library(RColorBrewer)
library(psych)
library(FactoMineR)
library(factoextra)
library(lattice)
library(MASS)
library(smacof)
library(tidyr)
library(corrplot)
library(texreg)
library(Hmisc)
library(fmsb)
library(lavaan)
library(semPlot)
library(semTable)
library(dotwhisker)
library(gridExtra)


#### Apply filters ####

# Attention check
df <- df[df$TE06_05 == 1, ]

# Control question (at the end of the survey)
df <- df[df$KO01 == "Ja, ich habe den Fragebogen aufmerksam und nach bestem Wissen und Gewissen beantwortet. Meine Angaben können zur Auswertung verwendet werden.", ]

# Speeding (at least 5 min. = 300 Sec.)
sum(df$TIME_SUM < 300, na.rm = T)
df <- df[df$TIME_SUM >= 300, ]



#### 1. Prepare variables ####

### 1.1 External and internal efficacy ####

# principal component analysis

pca.out <- principal(df[c("PL06_01", # inverted
                          "PL06_02",
                          "PL06_03",
                          "PL06_04", 
                          "PL06_05", # int. efficacy
                          "PL06_06", # int. efficacy
                          "PL06_07", # inverted
                          "PL06_08")], 
                     nfactors = 3, rotate="varimax")
pca.out$loadings # Factor 1 and 2 represent external and internal efficacy respectively; Item 8 loads on third dimension 

df$PL06_03r <- 6-df$PL06_03
df$PL06_07r <- 6-df$PL06_07


psych::alpha(df[c("PL06_01", 
                  "PL06_02",
                  "PL06_03r",
                  "PL06_04",
                  "PL06_07r") ],
             check.keys=TRUE) # Alpha is 0.81


df$disaffec <- apply( df[c( "PL06_01", 
                            "PL06_02",
                            "PL06_03r",
                            "PL06_04",
                            "PL06_07r")], 1, mean, na.rm=TRUE) # Create variable for external efficacy



#### 1.2 Political trust and satisfaction with democracy ####

psych::alpha(df[c("VT04_01",   
                  "VT04_02",
                  "VT04_03", 
                  "VT04_04",
                  "VT04_05") ],
             check.keys=TRUE) # Alpha is 0.92

df$poltrust <- apply( df[c( "VT04_01",   
                            "VT04_02",
                            "VT04_03", 
                            "VT04_04",
                            "VT04_05")], 1, mean, na.rm=TRUE)



df$VT06_01 # demsat




#### 1.3 Left right ideology ####

summary(df$PL01_01)
df$PL01_01 <- df$PL01_01-4 # center the left-right ideology variable



#### 1.4 vote intention ####
summary(df$PL07)
table(df$PL07)

factor(df$PL07) 
table(df$PL07)

df$PL07 <- factor(df$PL07, 
                  levels =  c("CDU/CSU", "SPD",
                              "B90/Die Grünen", "FDP", 
                              "Die Linke", "AfD",
                              "Andere:", "Würde nicht wählen", 
                              "[NA] Wei�\u009f nicht", "[NA] nicht beantwortet") )


#### 1.5 Political interest and sociodemographics ####

# political interest

df$polint <- as.numeric(df$VT05)

df$polint <- 6- df$polint

# education

df$education <- 0 
df$education[df$DG03 == "Fachhochschulreife (Abschluss einer Fachoberschule etc.)"] <- 1
df$education[df$DG03 == "Abitur bzw. erweiterte Oberschule mit Abschluss 12. Klasse (Hochschulreife)"] <- 1
table(df$education)

# gender

df$female <- 0
df$female[df$DG15 == "weiblich"] <- 1

# age

df$age




#### 2. Scaling analyses for items measuring conceptions of democracy ####

#### 2.1 Exploratory FA  (Annex A6 and A7)####

# limit dataframe to only conception variable
tmp <- df[ , c("DE05_01", # populist
               "DE05_02", # populist
               "DE05_03", # populist
               "DE05_04", # post-democratic
               "DE05_05", # post-democratic
               "DE05_06", # post-democratic
               "DE05_07", # technocratic
               "DE05_08", # technocratic
               "DE05_09", # technocratic
               "DE05_10", # majoritarian relativist
               "DE05_11", # majoritarian relativist
               "DE05_12"  # majoritarian relativist
               ) ]
tmp <- tmp[complete.cases(tmp), ]


fa.out <- factanal(tmp[c("DE05_01", # populist
                         "DE05_02", # populist
                         "DE05_03", # populist
                         "DE05_04", # post-democratic
                         "DE05_05", # post-democratic
                         "DE05_06", # post-democratic
                         "DE05_07", # technocratic
                         "DE05_08", # technocratic
                         "DE05_09", # technocratic
                         "DE05_10", # majoritarian relativist
                         "DE05_11", # majoritarian relativist
                         "DE05_12"  # majoritarian relativist
)], 
factors = 4, rotation = "promax")

fa.out$loadings
fa.out

KMO(tmp)

# write.csv(unclass(loadings(fa.out)), file = "efa.loadings_types1.csv")


tmp <- df[ , c("DE05_01", # populist
               "DE05_02", # populist
               "DE05_03", # populist
               "DE05_04", # post-democratic
               "DE05_05", # post-democratic
               "DE05_06", # post-democratic
               "DE05_07", # technocratic
               "DE05_08", # technocratic
               "DE05_09", # technocratic
               "DE05_10", # majoritarian relativist
               "DE05_11", # majoritarian relativist
               "DE05_12", # majoritarian relativist
               "DE08_01", # lib-dem: contestation
               "DE08_02",   
               "DE08_03",   
               "DE08_04", # lib-dem: pluralism
               "DE08_05",   
               "DE08_06",
               "DE08_07",
               "DE08_08") ]
tmp <- tmp[complete.cases(tmp), ]


fa.out <- factanal(tmp[c("DE05_01", # populist
                         "DE05_02", # populist
                         "DE05_03", # populist
                         "DE05_04", # post-democratic
                         "DE05_05", # post-democratic
                         "DE05_06", # post-democratic
                         "DE05_07", # technocratic
                         "DE05_08", # technocratic
                         "DE05_09", # technocratic
                         "DE05_10", # majoritarian relativist
                         "DE05_11", # majoritarian relativist
                         "DE05_12", # majoritarian relativist
                         "DE08_01", # lib-dem: contestation
                         "DE08_02",   
                         "DE08_03",   
                         "DE08_04", # lib-dem: pluralis
                         "DE08_05",   
                         "DE08_06",
                         "DE08_07",
                         "DE08_08")], 
                   factors = 6, rotation = "promax")

fa.out$loadings
fa.out

KMO(tmp)


# write.csv(unclass(loadings(fa.out)), file = "efa.loadings_types2.csv")



#### 2.2 Confirmatory FA (Annex A8) ####

# Confirmatory FA: with all items 

model <- '
  # measurement model

    populist  =~ DE05_01 + DE05_02 + DE05_03 
    
    postdemocratic  =~ DE05_04 + DE05_05 + DE05_06
    
    technocratic  =~  DE05_07 + DE05_09 + DE05_09
    
    majrel  =~ DE05_10 + DE05_11 + DE05_12
    
    libdem1 =~ DE08_01 + DE08_02 + DE08_03 + DE08_04
    
    libdem2 =~ DE08_05 + DE08_06 + DE08_07 + DE08_08
'


fit <- cfa(model, data = tmp, )

summary(fit, fit.measures=TRUE)

summary(fit, standardized = TRUE, rsq = T)



# Confirmatory FA: removing libdem_contestation-1 and technocratic-2

model <- '
  # measurement model

    populist  =~ DE05_01 + DE05_02 + DE05_03 
    
    postdemocratic  =~ DE05_04 + DE05_05 + DE05_06
    
    technocratic  =~  DE05_07 + DE05_09
    
    majrel  =~ DE05_10 + DE05_11 + DE05_12
    
    libdem1 =~ DE08_02 + DE08_03 + DE08_04
    
    libdem2 =~ DE08_05 + DE08_06 + DE08_07 + DE08_08
'


fit <- cfa(model, data = tmp, )

summary(fit, fit.measures=TRUE)

summary(fit, standardized = TRUE, rsq = T)


# semTable(fit, file = "cfa_out.csv", paramSets = "all",  columns = c(est = "Estimate", se = "SE", z = "z", p = "p"), fits = c("chisq", "cfi", "tli", "rmsea"), varLabels = NULL, groups = NULL, type = "csv")



#### 2.3 Generate conception variables ####

df$populist <- apply( df[c( "DE05_01", 
                            "DE05_02",
                            "DE05_03")], 1, mean, na.rm=TRUE)

df$postdem <- apply( df[c( "DE05_04", 
                           "DE05_05",
                           "DE05_06")], 1, mean, na.rm=TRUE)


df$technocratic <- apply( df[c( "DE05_07", 
                                "DE05_08", 
                                "DE05_09")], 1, mean, na.rm=TRUE)


# df$technocratic <- apply( df[c( "DE05_07", "DE05_09")], 1, mean, na.rm=TRUE) # 2 items

df$majrel <- apply( df[c( "DE05_10", 
                            "DE05_11",
                            "DE05_12")], 1, mean, na.rm=TRUE)



df$dynamic <- apply( df[c( "DE08_01",
                           "DE08_02", 
                           "DE08_03", 
                           "DE08_04")], 1, mean, na.rm=TRUE) 

#df$dynamic <- apply( df[c( "DE08_02", "DE08_03", "DE08_04")], 1, mean, na.rm=TRUE) # 3 items


df$pluralist <- apply( df[c( "DE08_05", 
                             "DE08_06",
                             "DE08_07",
                             "DE08_08")], 1, mean, na.rm=TRUE)


df$libdem <- (df$dynamic + df$pluralist)/2





#### 3. Describe the conception variables (Figure 2) ####

library(tidyr)
data_long <- gather(df, type, value, 
                    c(populist:majrel, libdem), 
                    factor_key=T)
data_long

data_long$type <- factor(data_long$type, labels = c("Populism", "Technocracy", "Majoritarian relativism", "Post-democracy", "Liberal democracy") )



# png(paste0("02_Figure_2_descriptives.png"), width=12, height=9,units="cm", res=400)

ggplot(data_long, aes(x = reorder(type, -as.numeric(type) ), y = value)) + geom_boxplot() + coord_flip() +
  xlab("") + ylab("Support for conceptions of democracy") + ylim(c(1,7)) + scale_y_continuous(breaks = 1:7) +  theme_bw()

# dev.off()



# pdf(paste0("02_Figure_2_descriptives.pdf"), width=6, height=5)

ggplot(data_long, aes(x = reorder(type, -as.numeric(type) ), y = value)) + geom_boxplot() + coord_flip() +
  xlab("") + ylab("Support for conceptions of democracy") + ylim(c(1,7)) + scale_y_continuous(breaks = 1:7) +  theme_bw()

# dev.off()






#### 4. Correlations (Figure 3) ####

cor.tmp <- df[c("libdem",
                "populist",
                "technocratic",
                "majrel",
                "postdem")]

cor.out <- rcorr(as.matrix(cor.tmp))

cor.out$r
cor.out$r2 <- round(cor.out$r, 2)
cor.out$P
cor.out$P2 <- cor.out$P
cor.out$P2[cor.out$P >= 0.05] <- ""
cor.out$P2[cor.out$P < 0.05] <- "*"
cor.out$P2[cor.out$P < 0.01] <- "**"
cor.out$P2 

# write.csv(as.matrix(cor.out$r2), file = "cor_matrix1.csv")
# write.csv(as.matrix(cor.out$P2), file = "cor_matrix2.csv")


# http://www.sthda.com/english/wiki/visualize-correlation-matrix-using-correlogram


corrplot(cor(cor.tmp, use = "complete"), method="circle", addCoef.col = 'grey')



wb = c('white', 'black')
corrplot(cor(cor.tmp, use = "complete"), col = wb, order = "hclust", outline = TRUE, cl.pos = 'n')
corrplot(cor(cor.tmp, use = "complete"), col = wb, type = "upper", outline = TRUE, cl.pos = 'n')


cor.mat <- cor(cor.tmp, use = "complete")

colnames(cor.mat) <- c("Liberal democracy",
                       "Populism", "Technocracy", "Majoritarian relativism", "Post-democracy"
                       )
rownames(cor.mat) <- colnames(cor.mat)



colnew <-  colorRampPalette(c("grey50","white", "grey50"))(10)  
colnew2 <-  colorRampPalette(c("grey20","white", "grey20"))(10)  



# png(paste0("03_Figure_3_corrplot.png"), width=12, height=12,units="cm", res=400)

corrplot(cor.mat, method = "ellipse", diag = F,
         col = colnew, addCoef.col = "black", number.cex = 0.6,
         type = "upper", outline = TRUE, cl.pos = 'n', tl.col = "black", insig = 'blank')

# dev.off()


# pdf(paste0("03_Figure_3_corrplot.pdf"), width=6, height=6)

corrplot(cor.mat, method = "ellipse", diag = F,
         col = colnew, addCoef.col = "black", number.cex = 0.6,
         type = "upper", outline = TRUE, cl.pos = 'n', tl.col = "black", insig = 'blank')

# dev.off()





#### 5. Create Types (Table 1) ####

#### 5.1 Types based on ordering / transitivity ####

df$puretype_1 <- 0
df$puretype_1[is.na(df$populist) == T |
               is.na(df$postdem) == T |
               is.na(df$technocratic) == T |
               is.na(df$majrel) == T |
               is.na(df$libdem) == T] <- NA
df$puretype_1[df$populist > df$postdem   &
               df$populist > df$technocratic &
               df$populist > df$majrel &
               df$populist > df$libdem ] <- 1
df$puretype_1[ df$postdem > df$populist &
                df$postdem > df$technocratic &
                df$postdem > df$majrel &
                df$postdem > df$libdem ] <- 3
df$puretype_1[ df$technocratic > df$populist &
                df$technocratic > df$postdem &
                df$technocratic >  df$majrel &
                df$technocratic > df$libdem] <- 2
df$puretype_1[df$majrel > df$populist & 
               df$majrel > df$postdem  &
               df$majrel > df$technocratic&
               df$majrel > df$libdem ] <- 4
df$puretype_1[df$libdem > df$populist & 
               df$libdem > df$postdem  &
               df$libdem > df$technocratic&
               df$libdem > df$majrel ] <- 5

table(df$puretype_1)
table(df$puretype_1)/sum(table(df$puretype_1))





####  5.2 Types based on means - one conception > mean , others <= mean  ####

df$populist_meansplit <- NA
df$populist_meansplit[df$populist <= mean(df$populist, na.rm=T)] <- 0
df$populist_meansplit[df$populist > mean(df$populist, na.rm=T)] <- 1

df$technocratic_meansplit <- NA
df$technocratic_meansplit[df$technocratic <= mean(df$technocratic, na.rm=T)] <- 0
df$technocratic_meansplit[df$technocratic > mean(df$technocratic, na.rm=T)] <- 1

df$postdem_meansplit <- NA
df$postdem_meansplit[df$postdem <= mean(df$postdem, na.rm=T)] <- 0
df$postdem_meansplit[df$postdem > mean(df$postdem, na.rm=T)] <- 1

df$majrel_meansplit <- NA
df$majrel_meansplit[df$majrel <= mean(df$majrel, na.rm=T)] <- 0
df$majrel_meansplit[df$majrel > mean(df$majrel, na.rm=T)] <- 1

df$libdem_meansplit <- NA
df$libdem_meansplit[df$libdem <= mean(df$libdem, na.rm=T)] <- 0
df$libdem_meansplit[df$libdem > mean(df$libdem, na.rm=T)] <- 1

table(df$populist_meansplit)



### combinations with only one conception above mean #

type.frame1 <- data.frame(
  
  labels = c("Populist ",
             "Technocratic",
             "Post-democratic",
             "Majoritarian-relativist",
             "Liberal-democratic"
             
  ),
  
  freq = c(
    
    sum(df$populist_meansplit == 1 & df$technocratic_meansplit == 0 & df$postdem_meansplit == 0 & df$majrel_meansplit == 0 & df$libdem_meansplit == 0 , na.rm = T ),
    sum(df$populist_meansplit == 0 & df$technocratic_meansplit == 1 & df$postdem_meansplit == 0 & df$majrel_meansplit == 0 & df$libdem_meansplit == 0 , na.rm = T),
    sum(df$populist_meansplit == 0 & df$technocratic_meansplit == 0 & df$postdem_meansplit == 1 & df$majrel_meansplit == 0 & df$libdem_meansplit == 0 , na.rm = T),
    sum(df$populist_meansplit == 0 & df$technocratic_meansplit == 0 & df$postdem_meansplit == 0 & df$majrel_meansplit == 1 & df$libdem_meansplit == 0 , na.rm = T),
    sum(df$populist_meansplit == 0 & df$technocratic_meansplit == 0 & df$postdem_meansplit == 0 & df$majrel_meansplit == 0 & df$libdem_meansplit == 1 , na.rm = T)
    
    
  )
 
  
)



type.frame1


# Append "Other"

sum(df$populist_meansplit >= 0 & df$technocratic_meansplit >= 0 & df$postdem_meansplit >= 0 & df$majrel_meansplit >= 0 & df$libdem_meansplit >= 0 , na.rm = T) - sum(type.frame1$freq)

type.frame1 <- rbind(type.frame1, 
       c("other", sum(df$populist_meansplit >= 0 & df$technocratic_meansplit >= 0 & df$postdem_meansplit >= 0 & df$majrel_meansplit >= 0 & df$libdem_meansplit >= 0 , na.rm = T) - sum(type.frame1$freq)
  )  )

type.frame1$freq  <- as.numeric(as.character ( type.frame1$freq ) )
type.frame1$freq / sum(type.frame1$freq)



# calculate all below mean
sum(df$populist_meansplit == 0 & df$technocratic_meansplit == 0 & df$postdem_meansplit == 0 & df$majrel_meansplit == 0 & df$libdem_meansplit == 0 , na.rm = T )
  




### Of category "Other": above mean on two (and only two) conceptions #

type.frame2 <- data.frame(
  
  labels = c("Populist & Technocratic ",
             "Populist & Post-democratic",
             "Populist & Majoritarian-relativist",
             "Populist & Liberal-democratic",
             "Technocratic & Post-democratic",
             "Technocratic & Majoritarian-relativist",
             "Technocratic & Liberal-democratic",
             "Post-democratic & Majoritarian-relativist",
             "Post-democratic & Liberal-democratic",
             "Majoritarian-relativist & Liberal-democratic"
             
  ),
  
  freq = c(
    
    sum(df$populist_meansplit == 1 & df$technocratic_meansplit == 1 & df$postdem_meansplit == 0 & df$majrel_meansplit == 0 & df$libdem_meansplit == 0 , na.rm = T ),
    sum(df$populist_meansplit == 1 & df$technocratic_meansplit == 0 & df$postdem_meansplit == 1 & df$majrel_meansplit == 0 & df$libdem_meansplit == 0 , na.rm = T),
    sum(df$populist_meansplit == 1 & df$technocratic_meansplit == 0 & df$postdem_meansplit == 0 & df$majrel_meansplit == 1 & df$libdem_meansplit == 0 , na.rm = T),
    sum(df$populist_meansplit == 1 & df$technocratic_meansplit == 0 & df$postdem_meansplit == 0 & df$majrel_meansplit == 0 & df$libdem_meansplit == 1 , na.rm = T),
    sum(df$populist_meansplit == 0 & df$technocratic_meansplit == 1 & df$postdem_meansplit == 1 & df$majrel_meansplit == 0 & df$libdem_meansplit == 0 , na.rm = T),
    sum(df$populist_meansplit == 0 & df$technocratic_meansplit == 1 & df$postdem_meansplit == 0 & df$majrel_meansplit == 1 & df$libdem_meansplit == 0 , na.rm = T),
    sum(df$populist_meansplit == 0 & df$technocratic_meansplit == 1 & df$postdem_meansplit == 0 & df$majrel_meansplit == 0 & df$libdem_meansplit == 1 , na.rm = T),
    sum(df$populist_meansplit == 0 & df$technocratic_meansplit == 0 & df$postdem_meansplit == 1 & df$majrel_meansplit == 1 & df$libdem_meansplit == 0 , na.rm = T),
    sum(df$populist_meansplit == 0 & df$technocratic_meansplit == 0 & df$postdem_meansplit == 1 & df$majrel_meansplit == 0 & df$libdem_meansplit == 1 , na.rm = T),
    sum(df$populist_meansplit == 0 & df$technocratic_meansplit == 0 & df$postdem_meansplit == 0 & df$majrel_meansplit == 1 & df$libdem_meansplit == 1 , na.rm = T)
    
    
  )
  
  
)

type.frame2
sum(type.frame2$freq)
type.frame2$freq / 704




### create types disregarding liberal-democratic #

type.frame1 <- data.frame(
  
  labels = c("Populist ",
             "Technocratic",
             "Post-democratic",
             "Majoritarian-relativist"
             
  ),
  
  freq = c(
    
    sum(df$populist_meansplit == 1 & df$technocratic_meansplit == 0 & df$postdem_meansplit == 0 & df$majrel_meansplit == 0  , na.rm = T ),
    sum(df$populist_meansplit == 0 & df$technocratic_meansplit == 1 & df$postdem_meansplit == 0 & df$majrel_meansplit == 0  , na.rm = T),
    sum(df$populist_meansplit == 0 & df$technocratic_meansplit == 0 & df$postdem_meansplit == 1 & df$majrel_meansplit == 0  , na.rm = T),
    sum(df$populist_meansplit == 0 & df$technocratic_meansplit == 0 & df$postdem_meansplit == 0 & df$majrel_meansplit == 1  , na.rm = T)
    
  )
  
  
)



type.frame1


# Append "Other"

sum(df$populist_meansplit >= 0 & df$technocratic_meansplit >= 0 & df$postdem_meansplit >= 0 & df$majrel_meansplit >= 0 & df$libdem_meansplit >= 0 , na.rm = T) - sum(type.frame1$freq)

type.frame1 <- rbind(type.frame1, 
                     c("other", sum(df$populist_meansplit >= 0 & df$technocratic_meansplit >= 0 & df$postdem_meansplit >= 0 & df$majrel_meansplit >= 0 & df$libdem_meansplit >= 0 , na.rm = T) - sum(type.frame1$freq)
                     )  )

type.frame1$freq  <- as.numeric(as.character ( type.frame1$freq ) )
type.frame1$freq / sum(type.frame1$freq)



# Of "Other": two above mean #

type.frame2 <- data.frame(
  
  labels = c("Populist & Technocratic ",
             "Populist & Post-democratic",
             "Populist & Majoritarian-relativist",
             "Technocratic & Post-democratic",
             "Technocratic & Majoritarian-relativist",
             "Post-democratic & Majoritarian-relativist"
             
  ),
  
  freq = c(
    
    sum(df$populist_meansplit == 1 & df$technocratic_meansplit == 1 & df$postdem_meansplit == 0 & df$majrel_meansplit == 0  , na.rm = T ),
    sum(df$populist_meansplit == 1 & df$technocratic_meansplit == 0 & df$postdem_meansplit == 1 & df$majrel_meansplit == 0  , na.rm = T),
    sum(df$populist_meansplit == 1 & df$technocratic_meansplit == 0 & df$postdem_meansplit == 0 & df$majrel_meansplit == 1  , na.rm = T),
    sum(df$populist_meansplit == 0 & df$technocratic_meansplit == 1 & df$postdem_meansplit == 1 & df$majrel_meansplit == 0  , na.rm = T),
    sum(df$populist_meansplit == 0 & df$technocratic_meansplit == 1 & df$postdem_meansplit == 0 & df$majrel_meansplit == 1  , na.rm = T),
    sum(df$populist_meansplit == 0 & df$technocratic_meansplit == 0 & df$postdem_meansplit == 1 & df$majrel_meansplit == 1  , na.rm = T)
   
    
  )
  
  
)

type.frame2
sum(type.frame2$freq)
type.frame2$freq / 668






#### 6. Multidimensional Scaling (Figure 4) ####

# All five conceptions of democracy

# Ipsatize variables first

df$populist.diff <- df$populist - ( df$populist + df$technocratic + df$postdem + df$majrel+ df$libdem)/5
df$technocratic.diff <- df$technocratic - ( df$technocratic + df$populist + df$majrel + df$postdem + df$libdem)/5
df$postdem.diff <- df$postdem - (df$postdem + df$technocratic + df$populist + df$majrel+ df$libdem)/5
df$majrel.diff <- df$majrel - ( df$majrel + df$postdem + df$technocratic + df$populist+ df$libdem)/5
df$libdem.diff <- df$libdem - ( df$majrel + df$postdem + df$technocratic + df$populist + df$libdem)/5

d <- dist( t(df[, c("populist.diff", "postdem.diff", "technocratic.diff", "majrel.diff", "libdem.diff"     ) ] ) , method = "euclidean" )           # find distance matrix 


fit <- mds(d, ndi = 2, type = "interval")
print(fit$stress)

tmp <- data.frame(fit$conf)
tmp$D1 <- -tmp$D1
colnames(tmp) <- c("D1", "D2")


# png(paste0("04_Figure_4_MDS.png"), width=16, height=8,units="cm", res=400)

ggplot(tmp, aes( x = D1, y = D2)) + geom_point(color = c(rep("black", 5)), 
                                               shape =  c(rep(16,  5) )  ,
                                               size = c(rep(2,  5) )   ) + 
  geom_segment(  aes( x = D1[1] , y = D2[1] , xend = D1[2] , yend = D2[2]   ) , linetype  = "dashed"  ,  colour = "grey20"  ) +
  geom_segment(  aes( x = D1[3] , y = D2[3] , xend = D1[4] , yend = D2[4]   ) , linetype  = "dashed"  ,  colour = "grey20"   ) +
  geom_text( aes ( label = c( "Populism", "Post-democracy", "Technocracy", "Majoritarian relativism", "Liberal democracy") , vjust = 2)  )  +
  ylim( c(  -0.6, 0.6 )  ) + xlim ( c(-1.2, 1.2) ) +
  theme_bw()

# dev.off()



# pdf(paste0("04_Figure_4_MDS.pdf"), width=5, height=5)

ggplot(tmp, aes( x = D1, y = D2)) + geom_point(color = c(rep("black", 5)), 
                                               shape =  c(rep(16,  5) )  ,
                                               size = c(rep(2,  5) )   ) + 
  geom_segment(  aes( x = D1[1] , y = D2[1] , xend = D1[2] , yend = D2[2]   ) , linetype  = "dashed"  ,  colour = "grey20"  ) +
  geom_segment(  aes( x = D1[3] , y = D2[3] , xend = D1[4] , yend = D2[4]   ) , linetype  = "dashed"  ,  colour = "grey20"   ) +
  geom_text( aes ( label = c( "Populism", "Post-\ndemocracy", "Technocracy", "Majoritarian relativism", "Liberal democracy") , vjust = 2) , nudge_y = c(0,0.05,0.1,0,0) )  +
  ylim( c(  -0.6, 0.6 )  ) + xlim ( c(-1.2, 1.2) ) +
  theme_bw()

# dev.off()





#### 7. Regress conceptions on independent variables (Figure 5, tables in Annex A9) ####

# generate relative support scores for the five conceptions of democracy

df$populist.diff <- df$populist - ( df$technocratic + df$postdem + df$majrel+ df$libdem)/4
df$technocratic.diff <- df$technocratic - ( df$populist + df$majrel + df$postdem+ df$libdem)/4
df$postdem.diff <- df$postdem - ( df$technocratic + df$populist + df$majrel+ df$libdem)/4
df$majrel.diff <- df$majrel - ( df$postdem + df$technocratic + df$populist+ df$libdem)/4
df$libdem.diff <- df$libdem - ( df$majrel + df$postdem + df$technocratic + df$populist )/4


#### 7.1 Populist conception ####
m1a <- lm(populist ~ disaffec + poltrust + VT06_01 +
            PL01_01 + I(PL01_01^2) + PL02_01 + PL03_01 + polint + age + factor(female) + education,
          data = df)

summary(m1a) 


m1b <- lm(populist.diff ~ disaffec + poltrust + VT06_01 +
            PL01_01 + I(PL01_01^2) + PL02_01 + PL03_01 + polint + age + factor(female) + education,
          data = df)

summary(m1b) 



#### 7.2 Technocratic conception ####
m2a <- lm(technocratic ~ disaffec + poltrust + VT06_01 +
            PL01_01 + I(PL01_01^2) + PL02_01 + PL03_01 + polint + age + factor(female) + education,
          data = df)

summary(m2a) 


m2b <- lm(technocratic.diff ~ disaffec + poltrust + VT06_01 +
            PL01_01 + I(PL01_01^2) + PL02_01 + PL03_01 + polint + age + factor(female) + education,
          data = df)

summary(m2b) 



#### 7.3 Post-democratic conception ####
m3a <- lm(postdem ~ disaffec + poltrust + VT06_01 +
            PL01_01 + I(PL01_01^2) + PL02_01 + PL03_01 + polint + age + factor(female) + education,
          data = df)

summary(m3a) 


m3b <- lm(postdem.diff ~ disaffec + poltrust + VT06_01 +
            PL01_01 + I(PL01_01^2) + PL02_01 + PL03_01 + polint + age + factor(female) + education,
          data = df)

summary(m3b) 



#### 7.4 Majoritarian-relativist conception ####
m4a <- lm(majrel ~ disaffec + poltrust + VT06_01 +
            PL01_01 + I(PL01_01^2) + PL02_01 + PL03_01 + polint + age + factor(female) + education,
          data = df)

summary(m4a) 


m4b <- lm(majrel.diff ~ disaffec + poltrust + VT06_01 +
            PL01_01 + I(PL01_01^2) + PL02_01 + PL03_01 + polint + age + factor(female) + education,
          data = df)

summary(m4b) 



#### 7.5 Liberal-democratic conception ####
m5a <- lm(libdem ~ disaffec + poltrust + VT06_01 +
            PL01_01 + I(PL01_01^2) + PL02_01 + PL03_01 + polint + age + factor(female) + education,
          data = df)

summary(m5a) 


m5b <- lm(libdem.diff ~ disaffec + poltrust + VT06_01 +
            PL01_01 + I(PL01_01^2)  + PL02_01 + PL03_01 + polint + age + factor(female) + education,
          data = df)

summary(m5b) 


# wordreg( list(m1a, m1b, m2a, m2b, m3a, m3b, m4a, m4b, m5a, m5b),   file = "Regressions_a.doc")





#### 7.6 Dot-whisker-plots ####
# Step 1: Create coefficient plot for each conception of democracy (with 2 models each).
# Step 2: Generate y-axis only for the first model.
# Step 3: Put all 5 graphs together horizontally into one figure. 

# https://cran.r-project.org/web/packages/dotwhisker/vignettes/dotwhisker-vignette.html


tmp <- m1a

modelframe1a <- data.frame(term = c(
  'Lack of\nexternal efficacy',
  'Political trust',
  'Satisfaction\nw. democracy',
  'Left-right',
  'Left-right squared',
  'Pro-state vs.\n market-liberal',
  'Anti- vs.pro-\nimmigration',
  'Political interest',
  'High formal\neducation'
),
estimate = c(  tmp$coefficients[2], tmp$coefficients[3],
               tmp$coefficients[4], tmp$coefficients[5],
               tmp$coefficients[6], tmp$coefficients[7], tmp$coefficients[8],
               tmp$coefficients[9], tmp$coefficients[12]),
std.error = c( coef(summary(tmp))[2, "Std. Error"], coef(summary(tmp))[3, "Std. Error"], 
               coef(summary(tmp))[4, "Std. Error"], coef(summary(tmp))[5, "Std. Error"], 
               coef(summary(tmp))[6, "Std. Error"], coef(summary(tmp))[7, "Std. Error"], coef(summary(tmp))[8, "Std. Error"], 
               coef(summary(tmp))[9, "Std. Error"], coef(summary(tmp))[12, "Std. Error"]
)
)



p1a <- dwplot(modelframe1a, 
              vline = geom_vline(xintercept = 0, colour = "grey60", linetype = 1)) + 
  theme_bw() + scale_colour_grey() + theme(legend.position = "none") + xlab("Coefficient") + ylab("")  


tmp <- m1b

modelframe1b <- data.frame(term = c(
  'Lack of\nexternal efficacy',
  'Political trust',
  'Satisfaction\nw. democracy',
  'Left-right',
  'Left-right squared',
  'Pro-state vs.\n market-liberal',
  'Anti- vs.pro-\nimmigration',
  'Political interest',
  'High formal\neducation'
),
estimate = c(  tmp$coefficients[2], tmp$coefficients[3],
               tmp$coefficients[4], tmp$coefficients[5],
               tmp$coefficients[6], tmp$coefficients[7], tmp$coefficients[8],
               tmp$coefficients[9], tmp$coefficients[12]),
std.error = c( coef(summary(tmp))[2, "Std. Error"], coef(summary(tmp))[3, "Std. Error"], 
               coef(summary(tmp))[4, "Std. Error"], coef(summary(tmp))[5, "Std. Error"], 
               coef(summary(tmp))[6, "Std. Error"], coef(summary(tmp))[7, "Std. Error"], coef(summary(tmp))[8, "Std. Error"], 
               coef(summary(tmp))[9, "Std. Error"], coef(summary(tmp))[12, "Std. Error"]
)
)




modelframe_allg <- rbind(modelframe1a, modelframe1b)

modelframe_allg$model <- rep(c("absolute", "relative"), each = 9)

modelframe_allg <- modelframe_allg[order(modelframe_allg$model, decreasing = T), ]


modelframe_allg$Measure <- factor (modelframe_allg$model, 
                                   levels = c("absolute", "relative"), 
                                   labels = c("absolute", "relative"))

p_r1 <- dwplot( modelframe_allg , 
                vline = geom_vline(xintercept = 0, colour = "grey60", linetype = 1), dot_args = list(aes(shape = model) , size = 2.5  )  ) + 
  theme_bw( ) + xlab("Coefficient") + ylab("") + ggtitle("Populism") + xlim( c(-0.8, 0.55) ) +
  theme(plot.title = element_text(face="bold"), title =  element_text(size=14),
        legend.position = "bottom", 
        axis.text.y = element_text(size=12), axis.title.x = element_text(size=12),
        legend.text = element_text(size=12), 
        legend.title = element_blank()) + scale_color_grey(name = "model", breaks=c("absolute", "relative") ) + 
  scale_shape_discrete(name = "Measure", breaks = c("absolute", "relative") )  +
  guides(
    shape = guide_legend("Measure"), 
    colour = guide_legend("Measure"),
    size = guide_legend("Measure")
  ) 





tmp <- m2a

modelframe2a <- data.frame(term = c(
  'Lack of\nexternal efficacy',
  'Political trust',
  'Satisfaction\nw. democracy',
  'Left-right',
  'Left-right squared',
  'Pro-state vs.\n market-liberal',
  'Anti- vs.pro-\nimmigration',
  'Political interest',
  'High formal\neducation'
),
estimate = c(  tmp$coefficients[2], tmp$coefficients[3],
               tmp$coefficients[4], tmp$coefficients[5],
               tmp$coefficients[6], tmp$coefficients[7], tmp$coefficients[8],
               tmp$coefficients[9], tmp$coefficients[12]),
std.error = c( coef(summary(tmp))[2, "Std. Error"], coef(summary(tmp))[3, "Std. Error"], 
               coef(summary(tmp))[4, "Std. Error"], coef(summary(tmp))[5, "Std. Error"], 
               coef(summary(tmp))[6, "Std. Error"], coef(summary(tmp))[7, "Std. Error"], coef(summary(tmp))[8, "Std. Error"], 
               coef(summary(tmp))[9, "Std. Error"], coef(summary(tmp))[12, "Std. Error"]
)
)





tmp <- m2b

modelframe2b <- data.frame(term = c(
  'Lack of\nexternal efficacy',
  'Political trust',
  'Satisfaction\nw. democracy',
  'Left-right',
  'Left-right squared',
  'Pro-state vs.\n market-liberal',
  'Anti- vs.pro-\nimmigration',
  'Political interest',
  'High formal\neducation'
),
estimate = c(  tmp$coefficients[2], tmp$coefficients[3],
               tmp$coefficients[4], tmp$coefficients[5],
               tmp$coefficients[6], tmp$coefficients[7], tmp$coefficients[8],
               tmp$coefficients[9], tmp$coefficients[12]),
std.error = c( coef(summary(tmp))[2, "Std. Error"], coef(summary(tmp))[3, "Std. Error"], 
               coef(summary(tmp))[4, "Std. Error"], coef(summary(tmp))[5, "Std. Error"], 
               coef(summary(tmp))[6, "Std. Error"], coef(summary(tmp))[7, "Std. Error"], coef(summary(tmp))[8, "Std. Error"], 
               coef(summary(tmp))[9, "Std. Error"], coef(summary(tmp))[12, "Std. Error"]
)
)




modelframe_allg <- rbind(modelframe2a, modelframe2b)

modelframe_allg$model <- rep(c("absolute", "relative"), each = 9)

modelframe_allg <- modelframe_allg[order(modelframe_allg$model, decreasing = T), ]


modelframe_allg$Measure <- factor (modelframe_allg$model, 
                                   levels = c("absolute", "relative"), 
                                   labels = c("absolute", "relative"))

p_r2<- dwplot( modelframe_allg , 
               vline = geom_vline(xintercept = 0, colour = "grey60", linetype = 1), dot_args = list(aes(shape = model) , size = 2.5  )  ) + 
  theme_bw( ) + xlab("Coefficient") + ylab("") +  ggtitle("Technocracy") + xlim( c(-0.8, 0.55) ) +
  theme(plot.title = element_text(face="bold"), title =  element_text(size=14),
        legend.position = "bottom", axis.text.y=element_blank(),
        axis.title.x = element_text(size=12),
        legend.text = element_text(size=12), 
        legend.title = element_blank() ) + scale_color_grey(name = "model", breaks=c("absolute", "relative") ) + 
  scale_shape_discrete(name = "Measure", breaks = c("absolute", "relative") )  +
  guides(
    shape = guide_legend("Measure"), 
    colour = guide_legend("Measure"),
    size = guide_legend("Measure")
  ) 




tmp <- m3a

modelframe3a <- data.frame(term = c(
  'Lack of\nexternal efficacy',
  'Political trust',
  'Satisfaction\nw. democracy',
  'Left-right',
  'Left-right squared',
  'Pro-state vs.\n market-liberal',
  'Anti- vs.pro-\nimmigration',
  'Political interest',
  'High formal\neducation'
),
estimate = c(  tmp$coefficients[2], tmp$coefficients[3],
               tmp$coefficients[4], tmp$coefficients[5],
               tmp$coefficients[6], tmp$coefficients[7], tmp$coefficients[8],
               tmp$coefficients[9], tmp$coefficients[12]),
std.error = c( coef(summary(tmp))[2, "Std. Error"], coef(summary(tmp))[3, "Std. Error"], 
               coef(summary(tmp))[4, "Std. Error"], coef(summary(tmp))[5, "Std. Error"], 
               coef(summary(tmp))[6, "Std. Error"], coef(summary(tmp))[7, "Std. Error"], coef(summary(tmp))[8, "Std. Error"], 
               coef(summary(tmp))[9, "Std. Error"], coef(summary(tmp))[12, "Std. Error"]
)
)





tmp <- m3b

modelframe3b <- data.frame(term = c(
  'Lack of\nexternal efficacy',
  'Political trust',
  'Satisfaction\nw. democracy',
  'Left-right',
  'Left-right squared',
  'Pro-state vs.\n market-liberal',
  'Anti- vs.pro-\nimmigration',
  'Political interest',
  'High formal\neducation'
),
estimate = c(  tmp$coefficients[2], tmp$coefficients[3],
               tmp$coefficients[4], tmp$coefficients[5],
               tmp$coefficients[6], tmp$coefficients[7], tmp$coefficients[8],
               tmp$coefficients[9], tmp$coefficients[12]),
std.error = c( coef(summary(tmp))[2, "Std. Error"], coef(summary(tmp))[3, "Std. Error"], 
               coef(summary(tmp))[4, "Std. Error"], coef(summary(tmp))[5, "Std. Error"], 
               coef(summary(tmp))[6, "Std. Error"], coef(summary(tmp))[7, "Std. Error"], coef(summary(tmp))[8, "Std. Error"], 
               coef(summary(tmp))[9, "Std. Error"], coef(summary(tmp))[12, "Std. Error"]
)
)





modelframe_allg <- rbind(modelframe3a, modelframe3b)

modelframe_allg$model <- rep(c("absolute", "relative"), each = 9)

modelframe_allg <- modelframe_allg[order(modelframe_allg$model, decreasing = T), ]


modelframe_allg$Measure <- factor (modelframe_allg$model, 
                                   levels = c("absolute", "relative"), 
                                   labels = c("absolute", "relative"))

p_r3<- dwplot( modelframe_allg , 
               vline = geom_vline(xintercept = 0, colour = "grey60", linetype = 1), dot_args = list(aes(shape = model) , size = 2.5  )  ) + 
  theme_bw( ) + xlab("Coefficient") + ylab("") +  ggtitle("Post-democracy") + xlim( c(-0.8, 0.55) ) +
  theme(plot.title = element_text(face="bold"), title =  element_text(size=14),
        legend.position = "bottom", axis.text.y=element_blank(),
        axis.title.x = element_text(size=12),
        legend.text = element_text(size=12), 
        legend.title = element_blank() ) + scale_color_grey(name = "model", breaks=c("absolute", "relative") ) + 
  scale_shape_discrete(name = "Measure", breaks = c("absolute", "relative") )  +
  guides(
    shape = guide_legend("Measure"), 
    colour = guide_legend("Measure"),
    size = guide_legend("Measure")
  ) 





tmp <- m4a

modelframe4a <- data.frame(term = c(
  'Lack of\nexternal efficacy',
  'Political trust',
  'Satisfaction\nw. democracy',
  'Left-right',
  'Left-right squared',
  'Pro-state vs.\n market-liberal',
  'Anti- vs.pro-\nimmigration',
  'Political interest',
  'High formal\neducation'
),
estimate = c(  tmp$coefficients[2], tmp$coefficients[3],
               tmp$coefficients[4], tmp$coefficients[5],
               tmp$coefficients[6], tmp$coefficients[7], tmp$coefficients[8],
               tmp$coefficients[9], tmp$coefficients[12]),
std.error = c( coef(summary(tmp))[2, "Std. Error"], coef(summary(tmp))[3, "Std. Error"], 
               coef(summary(tmp))[4, "Std. Error"], coef(summary(tmp))[5, "Std. Error"], 
               coef(summary(tmp))[6, "Std. Error"], coef(summary(tmp))[7, "Std. Error"], coef(summary(tmp))[8, "Std. Error"], 
               coef(summary(tmp))[9, "Std. Error"], coef(summary(tmp))[12, "Std. Error"]
)
)





tmp <- m4b

modelframe4b <- data.frame(term = c(
  'Lack of\nexternal efficacy',
  'Political trust',
  'Satisfaction\nw. democracy',
  'Left-right',
  'Left-right squared',
  'Pro-state vs.\n market-liberal',
  'Anti- vs.pro-\nimmigration',
  'Political interest',
  'High formal\neducation'
),
estimate = c(  tmp$coefficients[2], tmp$coefficients[3],
               tmp$coefficients[4], tmp$coefficients[5],
               tmp$coefficients[6], tmp$coefficients[7], tmp$coefficients[8],
               tmp$coefficients[9], tmp$coefficients[12]),
std.error = c( coef(summary(tmp))[2, "Std. Error"], coef(summary(tmp))[3, "Std. Error"], 
               coef(summary(tmp))[4, "Std. Error"], coef(summary(tmp))[5, "Std. Error"], 
               coef(summary(tmp))[6, "Std. Error"], coef(summary(tmp))[7, "Std. Error"], coef(summary(tmp))[8, "Std. Error"], 
               coef(summary(tmp))[9, "Std. Error"], coef(summary(tmp))[12, "Std. Error"]
)
)





modelframe_allg <- rbind(modelframe4a, modelframe4b)

modelframe_allg$model <- rep(c("absolute", "relative"), each = 9)

modelframe_allg <- modelframe_allg[order(modelframe_allg$model, decreasing = T), ]


modelframe_allg$Measure <- factor (modelframe_allg$model, 
                                   levels = c("absolute", "relative"), 
                                   labels = c("absolute", "relative"))

p_r4<- dwplot( modelframe_allg , 
               vline = geom_vline(xintercept = 0, colour = "grey60", linetype = 1), dot_args = list(aes(shape = model) , size = 2.5  )  ) + 
  theme_bw( ) + xlab("Coefficient") + ylab("") +  ggtitle("Majoritarian relativism") + xlim( c(-0.8, 0.55) ) +
  theme(plot.title = element_text(face="bold"), title =  element_text(size=14),
        legend.position = "bottom", axis.text.y=element_blank(),
        axis.title.x = element_text(size=12),
        legend.text = element_text(size=12), 
        legend.title = element_blank() ) + scale_color_grey(name = "model", breaks=c("absolute", "relative") ) + 
  scale_shape_discrete(name = "Measure", breaks = c("absolute", "relative") )  +
  guides(
    shape = guide_legend("Measure"), 
    colour = guide_legend("Measure"),
    size = guide_legend("Measure")
  ) 






tmp <- m5a

modelframe5a <- data.frame(term = c(
  'Political\ndisaffection',
  'Political trust',
  'Satisfaction\nw. democracy',
  'Left-right',
  'Left-right squared',
  'Pro-state vs.\n market-liberal',
  'Anti- vs.pro-\nimmigration',
  'Political interest',
  'High formal\neducation'
),
estimate = c(  tmp$coefficients[2], tmp$coefficients[3],
               tmp$coefficients[4], tmp$coefficients[5],
               tmp$coefficients[6], tmp$coefficients[7], tmp$coefficients[8],
               tmp$coefficients[9], tmp$coefficients[12]),
std.error = c( coef(summary(tmp))[2, "Std. Error"], coef(summary(tmp))[3, "Std. Error"], 
               coef(summary(tmp))[4, "Std. Error"], coef(summary(tmp))[5, "Std. Error"], 
               coef(summary(tmp))[6, "Std. Error"], coef(summary(tmp))[7, "Std. Error"], coef(summary(tmp))[8, "Std. Error"], 
               coef(summary(tmp))[9, "Std. Error"], coef(summary(tmp))[12, "Std. Error"]
)
)






tmp <- m5b

modelframe5b <- data.frame(term = c(
  'Political\ndisaffection',
  'Political trust',
  'Satisfaction\nw. democracy',
  'Left-right',
  'Left-right squared',
  'Pro-state vs.\n market-liberal',
  'Anti- vs.pro-\nimmigration',
  'Political interest',
  'High formal\neducation'
),
estimate = c(  tmp$coefficients[2], tmp$coefficients[3],
               tmp$coefficients[4], tmp$coefficients[5],
               tmp$coefficients[6], tmp$coefficients[7], tmp$coefficients[8],
               tmp$coefficients[9], tmp$coefficients[12]),
std.error = c( coef(summary(tmp))[2, "Std. Error"], coef(summary(tmp))[3, "Std. Error"], 
               coef(summary(tmp))[4, "Std. Error"], coef(summary(tmp))[5, "Std. Error"], 
               coef(summary(tmp))[6, "Std. Error"], coef(summary(tmp))[7, "Std. Error"], coef(summary(tmp))[8, "Std. Error"], 
               coef(summary(tmp))[9, "Std. Error"], coef(summary(tmp))[12, "Std. Error"]
)
)




modelframe_allg <- rbind(modelframe5a, modelframe5b)

modelframe_allg$model <- rep(c("absolute", "relative"), each = 9)

modelframe_allg <- modelframe_allg[order(modelframe_allg$model, decreasing = T), ]


modelframe_allg$Measure <- factor (modelframe_allg$model, 
                                   levels = c("absolute", "relative"), 
                                   labels = c("absolute", "relative"))

p_r5<- dwplot( modelframe_allg , 
               vline = geom_vline(xintercept = 0, colour = "grey60", linetype = 1), dot_args = list(aes(shape = model) , size = 2.5  )  ) + 
  theme_bw( ) + xlab("Coefficient") + ylab("") +  ggtitle("Liberal democracy") + xlim( c(-0.8, 0.55) ) +
  theme(plot.title = element_text(face="bold"), title =  element_text(size=14),
        legend.position = "bottom", axis.text.y=element_blank(),
        axis.title.x = element_text(size=12),
        legend.text = element_text(size=12), 
        legend.title = element_blank() ) + scale_color_grey(name = "model", breaks=c("absolute", "relative") ) + 
  scale_shape_discrete(name = "Measure", breaks = c("absolute", "relative") )  +
  guides(
    shape = guide_legend("Measure"), 
    colour = guide_legend("Measure"),
    size = guide_legend("Measure")
  ) 





# png(paste0("05_Figure_5_dotwhisker.png"), width=36, height=12, units="cm", res=400)

grid.arrange(p_r1, p_r2, p_r4, p_r3, p_r5,
             widths = c(1.4, 1, 1, 1, 1),
             ncol = 5)

# dev.off()




# pdf(paste0("05_Figure_5_dotwhisker.pdf"), width=16, height=8)

grid.arrange(p_r1, p_r2, p_r4,  p_r3, p_r5,
             widths = c(1.4, 1, 1, 1, 1),
             ncol = 5 )

# dev.off()








#### 8. Additional analyses ####

#### 8.1 Additional models without u-shaped left right ####

# generate relative support scores for the five conceptions of democracy

df$populist.diff <- df$populist - ( df$technocratic + df$postdem + df$majrel+ df$libdem)/4
df$technocratic.diff <- df$technocratic - ( df$populist + df$majrel + df$postdem+ df$libdem)/4
df$postdem.diff <- df$postdem - ( df$technocratic + df$populist + df$majrel+ df$libdem)/4
df$majrel.diff <- df$majrel - ( df$postdem + df$technocratic + df$populist+ df$libdem)/4
df$libdem.diff <- df$libdem - ( df$majrel + df$postdem + df$technocratic + df$populist )/4



# Populist conception
m1a <- lm(populist ~ disaffec + poltrust + VT06_01 +
            PL01_01 + PL02_01 + PL03_01 + polint + age + factor(female) + education,
          data = df)

summary(m1a) 


m1b <- lm(populist.diff ~ disaffec + poltrust + VT06_01 +
            PL01_01 + PL02_01 + PL03_01 + polint + age + factor(female) + education,
          data = df)

summary(m1b) 



# Technocratic conception
m2a <- lm(technocratic ~ disaffec + poltrust + VT06_01 +
            PL01_01 + PL02_01 + PL03_01 + polint + age + factor(female) + education,
          data = df)

summary(m2a) 


m2b <- lm(technocratic.diff ~ disaffec + poltrust + VT06_01 +
            PL01_01 + PL02_01 + PL03_01 + polint + age + factor(female) + education,
          data = df)

summary(m2b) 



# Post-democratic conception
m3a <- lm(postdem ~ disaffec + poltrust + VT06_01 +
            PL01_01 + PL02_01 + PL03_01 + polint + age + factor(female) + education,
          data = df)

summary(m3a) 


m3b <- lm(postdem.diff ~ disaffec + poltrust + VT06_01 +
            PL01_01 + PL02_01 + PL03_01 + polint + age + factor(female) + education,
          data = df)

summary(m3b) 



# Majoritarian-relativist conception
m4a <- lm(majrel ~ disaffec + poltrust + VT06_01 +
            PL01_01 + PL02_01 + PL03_01 + polint + age + factor(female) + education,
          data = df)

summary(m4a) 


m4b <- lm(majrel.diff ~ disaffec + poltrust + VT06_01 +
            PL01_01 + PL02_01 + PL03_01 + polint + age + factor(female) + education,
          data = df)

summary(m4b) 



#  Liberal-democratic conception
m5a <- lm(libdem ~ disaffec + poltrust + VT06_01 +
            PL01_01 + PL02_01 + PL03_01 + polint + age + factor(female) + education,
          data = df)

summary(m5a) 


m5b <- lm(libdem.diff ~ disaffec + poltrust + VT06_01 +
            PL01_01 + PL02_01 + PL03_01 + polint + age + factor(female) + education,
          data = df)

summary(m5b) 


# wordreg( list(m1a, m1b, m2a, m2b, m3a, m3b, m4a, m4b, m5a, m5b),   file = "Regressions_no_leftright_u.doc")





#### 8.2 Additional models with vote choice as an additional independent variable (Annex A10) ####

# generate relative support scores for the five conceptions of democracy

df$populist.diff <- df$populist - ( df$technocratic + df$postdem + df$majrel+ df$libdem)/4
df$technocratic.diff <- df$technocratic - ( df$populist + df$majrel + df$postdem+ df$libdem)/4
df$postdem.diff <- df$postdem - ( df$technocratic + df$populist + df$majrel+ df$libdem)/4
df$majrel.diff <- df$majrel - ( df$postdem + df$technocratic + df$populist+ df$libdem)/4
df$libdem.diff <- df$libdem - ( df$majrel + df$postdem + df$technocratic + df$populist )/4




# Populist conception
m1a <- lm(populist ~ disaffec + poltrust + VT06_01 +
            PL01_01 + I(PL01_01^2) + PL02_01 + PL03_01 + factor(PL07) + polint + age + factor(female) + education,
          data = df)

summary(m1a) 


m1b <- lm(populist.diff ~ disaffec + poltrust + VT06_01 +
            PL01_01 + I(PL01_01^2) + PL02_01 + PL03_01 + factor(PL07) + polint + age + factor(female) + education,
          data = df)

summary(m1b) 



# Technocratic conception
m2a <- lm(technocratic ~ disaffec + poltrust + VT06_01 +
            PL01_01 + I(PL01_01^2) +  PL02_01 + PL03_01 + factor(PL07) + polint + age + factor(female) + education,
          data = df)

summary(m2a) 


m2b <- lm(technocratic.diff ~ disaffec + poltrust + VT06_01 +
            PL01_01 + I(PL01_01^2) + PL02_01 + PL03_01 + factor(PL07) + polint + age + factor(female) + education,
          data = df)

summary(m2b) 



# Post-democratic conception
m3a <- lm(postdem ~ disaffec + poltrust + VT06_01 +
            PL01_01 + I(PL01_01^2) + PL02_01 + PL03_01 + factor(PL07) + polint + age + factor(female) + education,
          data = df)

summary(m3a) 


m3b <- lm(postdem.diff ~ disaffec + poltrust + VT06_01 +
            PL01_01 + I(PL01_01^2) + PL02_01 + PL03_01 + factor(PL07) + polint + age + factor(female) + education,
          data = df)

summary(m3b) 



# Political-nihilist conception
m4a <- lm(majrel ~ disaffec + poltrust + VT06_01 +
            PL01_01 + I(PL01_01^2) + PL02_01 + PL03_01 + factor(PL07) + polint + age + factor(female) + education,
          data = df)

summary(m4a) 


m4b <- lm(majrel.diff ~ disaffec + poltrust + VT06_01 +
            PL01_01 + I(PL01_01^2) + PL02_01 + PL03_01 + factor(PL07) + polint + age + factor(female) + education,
          data = df)

summary(m4b) 



#  Liberal-democratic conception
m5a <- lm(libdem ~ disaffec + poltrust + VT06_01 +
            PL01_01 + I(PL01_01^2) + PL02_01 + PL03_01 + factor(PL07) + polint + age + factor(female) + education,
          data = df)

summary(m5a) 


m5b <- lm(libdem.diff ~ disaffec + poltrust + VT06_01 +
            PL01_01 + I(PL01_01^2) + PL02_01 + PL03_01 + factor(PL07) + polint + age + factor(female) + education,
          data = df)

summary(m5b) 


# wordreg( list(m1a, m1b, m2a, m2b, m3a, m3b, m4a, m4b, m5a, m5b),   file = "Regressions_annex10.doc")






#### 8.3 Models with only left right - without economic and immigration policy preferences (Annex A11) ####


# generate relative support scores for the five conceptions of democracy

df$populist.diff <- df$populist - ( df$technocratic + df$postdem + df$majrel+ df$libdem)/4
df$technocratic.diff <- df$technocratic - ( df$populist + df$majrel + df$postdem+ df$libdem)/4
df$postdem.diff <- df$postdem - ( df$technocratic + df$populist + df$majrel+ df$libdem)/4
df$majrel.diff <- df$majrel - ( df$postdem + df$technocratic + df$populist+ df$libdem)/4
df$libdem.diff <- df$libdem - ( df$majrel + df$postdem + df$technocratic + df$populist )/4


# Populist conception
m1a <- lm(populist ~ disaffec + poltrust + VT06_01 +
            PL01_01 + polint + age + factor(female) + education,
          data = df)

summary(m1a) 


m1b <- lm(populist.diff ~ disaffec + poltrust + VT06_01 +
            PL01_01 +  polint + age + factor(female) + education,
          data = df)

summary(m1b) 



# Technocratic conception
m2a <- lm(technocratic ~ disaffec + poltrust + VT06_01 +
            PL01_01 +   polint + age + factor(female) + education,
          data = df)

summary(m2a) 


m2b <- lm(technocratic.diff ~ disaffec + poltrust + VT06_01 +
            PL01_01 + polint + age + factor(female) + education,
          data = df)

summary(m2b) 



# Post-democratic conception
m3a <- lm(postdem ~ disaffec + poltrust + VT06_01 +
            PL01_01 +   polint + age + factor(female) + education,
          data = df)

summary(m3a) 


m3b <- lm(postdem.diff ~ disaffec + poltrust + VT06_01 +
            PL01_01 +   polint + age + factor(female) + education,
          data = df)

summary(m3b) 



# Political-nihilist conception
m4a <- lm(majrel ~ disaffec + poltrust + VT06_01 +
            PL01_01 + polint + age + factor(female) + education,
          data = df)

summary(m4a) 


m4b <- lm(majrel.diff ~ disaffec + poltrust + VT06_01 +
            PL01_01 + polint + age + factor(female) + education,
          data = df)

summary(m4b) 



#  Liberal-democratic conception
m5a <- lm(libdem ~ disaffec + poltrust + VT06_01 +
            PL01_01 +  polint + age + factor(female) + education,
          data = df)

summary(m5a) 


m5b <- lm(libdem.diff ~ disaffec + poltrust + VT06_01 +
            PL01_01 +   polint + age + factor(female) + education,
          data = df)

summary(m5b) 


# wordreg( list(m1a, m1b, m2a, m2b, m3a, m3b, m4a, m4b, m5a, m5b),   file = "Regressions_only_LR.doc")





#### 8.4 Inspect whether political support shows a curvi-linear relation with left-right ideology ####

df$PL01_01sq <- df$PL01_01^2

cor(df[, c( "PL01_01sq",  "disaffec", "poltrust", "VT06_01" ) ], 
    use = "complete"   )

# estiamte  model with populist conception of democracy as DV without variables for political support

m1a <- lm(populist ~ 
            PL01_01 + I(PL01_01^2) + polint + age + factor(female) + education,
          data = df)

summary(m1a) 


m1b <- lm(populist.diff ~ 
            PL01_01 + I(PL01_01^2) +  polint + age + factor(female) + education,
          data = df)

summary(m1b) 


# wordreg( list(m1a, m1b),   file = "Regressions_LR_populism.doc")



